package com.darren.euc.action;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.darren.euc.entity.PrintRecord;
import com.darren.euc.entity.Member;
import com.darren.euc.entity.PageBean;
import com.darren.euc.entity.ResponseJSON;
import com.darren.euc.service.PrintRecordService;
import com.darren.euc.util.PropertyHelper;

import net.sf.json.JSONObject;

@Controller
@RequestMapping("/print")
public class PrintRecordAction {
	
	private static final Logger log = Logger.getLogger(PrintRecordAction.class);

	@Autowired
    private PrintRecordService pintRecordService;
	
	@ResponseBody
    @RequestMapping(value = "/list")//,method = RequestMethod.POST)
    public List<PrintRecord> getAll(HttpServletRequest request,HttpServletResponse response) {
    	List<PrintRecord> printRecords = pintRecordService.getAll();    	
        return printRecords;
    }
	
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value = "/query",method = RequestMethod.POST)
    public ResponseJSON queryPrintRecord(@RequestBody JSONObject requestJson,HttpServletRequest request,HttpServletResponse response) {	
		ResponseJSON responseJson = new ResponseJSON();
		PageBean pageBean = pintRecordService.queryPrintRecordForPageUseHQL(requestJson.getJSONObject("data"), PropertyHelper.getPageSize(), requestJson.getInt("currentPage"));
		responseJson.setData(pageBean);
		return responseJson;
    }
	
	@SuppressWarnings("rawtypes")
	@ResponseBody
    @RequestMapping(value = "/myprint",method = RequestMethod.POST)
    public ResponseJSON queryMyPrintRecord(@RequestBody JSONObject requestJson,HttpServletRequest request,HttpServletResponse response) {	
		Member member = (Member) request.getAttribute("member");
		ResponseJSON responseJson = new ResponseJSON();
		requestJson.getJSONObject("data").getJSONObject("equals").put("memberId", member.getId());
		PageBean pageBean = pintRecordService.queryPrintRecordForPageUseHQL(requestJson.getJSONObject("data"), PropertyHelper.getPageSize(), requestJson.getInt("currentPage"));
		responseJson.setData(pageBean);
		return responseJson;
    }
	
}